package com.aop;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

/**
 * @author cyt
 * @date 2020/9/19
 */

@Aspect
@Component
public class AopDemo {

    @Pointcut("execution(* com.service.*.*(..))")
    public void myPoint(){}


    @Before("AopDemo.myPoint()")
    public void before() {
        System.out.println("前置通知...");

    }

    @Around("AopDemo.myPoint()")
    public void around(ProceedingJoinPoint pjp){

        try {
            System.out.println("环绕通知的前置通知");

            pjp.proceed();

            System.out.println("环绕通知的后置通知");
        } catch (Throwable throwable) {
            throwable.printStackTrace();
        }finally {
            System.out.println("环绕通知的最终通知");
        }

    }


}
